#include<bits/stdc++.h>
#define int long long 
#define Maxn 400005 
using namespace std;
map<int,bool> mp;
set<int> S;
signed main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T; cin>>T;
	while(T --) {
		int x; cin>>x;
		if(mp[x])mp[x] = false,S.erase(x);
		else mp[x] = true,S.insert(x);
		int sum1 = 0,sum2 = 0,ans = 0,low = 0;
		auto p = S.begin(),q = S.end(); q --;
		for(int len=1;len<(int)S.size();len++) {
			sum1 += (*p);
			sum2 += (*q);
			low = max(sum1,low);
			ans += sum2-low;
			low = sum2;
//			cout<<low<<" "<<sum2<<"\n";
			p ++; q --;
		} cout<<ans<<"\n";
	}
	return 0;
 } 
